﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WWWSiteHelper
{
    public partial class NewProjectDialog : Form
    {
        public NewProjectDialog()
        {
            InitializeComponent();
            typeComboBox.SelectedIndex = 0;
        }

        private void viewUpdate(object sender, EventArgs e) 
        {
            if (nameTextBox.Text.Equals("") || localPathTextBox.Text.Equals("") || !Directory.Exists(localPathTextBox.Text)) 
                okButton.Enabled = false;
            else
                okButton.Enabled = true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ProjectId newProject = null;
            switch (typeComboBox.SelectedIndex)
            {
                case 0:
                     newProject = new LocalProjectId(localPathTextBox.Text+"\\"+nameTextBox.Text+ProjectId.ProjectFileExtension);
                    break;
                case 1:
                    newProject = new SshProjectId();
                    break;
            }
            newProject.CreateProject(nameTextBox.Text);
            ((MainForm)this.Owner).CurrentProject = newProject.LoadProject();
            Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void typeComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            // TODO change to visible & resize
            switch (typeComboBox.SelectedIndex)
            {
                case 0:
                    sshPanel.Enabled = false;
                    localPanel.Enabled = true;
                    break;
                case 1:
                    localPanel.Enabled = false;
                    sshPanel.Enabled = true;
                    break;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DialogResult result = localFolderDialog.ShowDialog(this);
            if (DialogResult.OK.Equals(result))
            {
                localPathTextBox.Text = localFolderDialog.SelectedPath;
            }
        }
    }
}
